package com.jackaltsc.mydemolist.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jackaltsc.mydemolist.R;

import java.util.List;

/**
 * RecyclerView的适配器
 * Created by JackalTsc on 2016/7/13.
 */

public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.MyViewHolder> {

    private List<String> mData;
    private LayoutInflater mInflater;

    public RecyclerAdapter(Context context, List<String> data) {
        mData = data;
        mInflater = LayoutInflater.from(context);
    }

    //生成ViewHolder
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        MyViewHolder holder = new MyViewHolder(mInflater.inflate(R.layout.view_item_recycler,
                parent, false));
        return holder;
    }

    //刷新数据
    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.tvNum.setText(mData.get(position));
    }

    //数据集合数量
    @Override
    public int getItemCount() {
        return mData.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        TextView tvNum;

        public MyViewHolder(View view) {
            super(view);
            tvNum = (TextView) view.findViewById(R.id.tv_num);
        }
    }

}

